package org.flashbrighton.as3bots.bots
{	
	import flash.display.Sprite;
	
	import org.flashbrighton.as3bots.components.*;
	import org.flashbrighton.as3bots.controllers.IBotController;
	import org.flashbrighton.as3bots.models.BotModel;
		
	public class BaseBot
	{
		public var botName:String;
		
		private var _model:BotModel;
		private var _controller:IBotController;		
		private var _components:Vector.<IComponent>;
		private var _engine:EngineComponent;
		private var _health:HealthComponent;
		private var _steering:SteeringComponent;
		private var _chassis:ChassisComponent;
		
		
		public function BaseBot()
		{
			setModel();
			_components = new Vector.<IComponent>();
		}
		

		public function addEngineComponent():void
		{
			_engine = new EngineComponent();
			addComponent(_engine);
		}
		
		
		public function addHealthComponent():void
		{
			_health = new HealthComponent();
			addComponent(_health);
		}
		
		
		public function addSteeringComponent():void
		{
			_steering = new SteeringComponent();
			addComponent(_steering);
		}
		
		
		public function addBodyComponent(size:String=ChassisSize.MEDIUM, skinImage:Sprite=null):void
		{
			_chassis = new ChassisComponent(size, skinImage);
			addComponent(_chassis);
		}
		
		
		public function setController(controller:IBotController):void
		{
			_controller = controller;
		}
		
		
		public function get engine():EngineComponent
		{
			return _engine;
		}
		
		
		public function get health():HealthComponent
		{
			return _health;
		}
		
		
		public function get steering():SteeringComponent
		{
			return _steering;
		}
		
		
		public function get chassis():ChassisComponent
		{
			return _chassis;
		}
		
		
		public function get model():BotModel
		{
			return _model;
		}
		
		
		public function get controller():IBotController
		{
			return _controller;
		}
		
		
		private function setModel():void
		{
			_model = new BotModel();
		}
		
		
		private function addComponent(component:IComponent):void
		{
			if (_components.length == 5) throw new Error("A bot cannot hold more than 5 components.");
			_components.push(component);
		}
		
	}
}